- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1  D a t e   q u e r y   a f t e r   a d d i n g   Y e a r   M o n t h   N u m b e r 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 l e t 
 
         S o u r c e   =   S q l . D a t a b a s e s ( " l o c a l h o s t " ) , 
 
         W i d e W o r l d I m p o r t e r s D W   =   S o u r c e { [ N a m e = " W i d e W o r l d I m p o r t e r s D W " ] } [ D a t a ] , 
 
         D i m e n s i o n _ D a t e   =   W i d e W o r l d I m p o r t e r s D W { [ S c h e m a = " D i m e n s i o n " , I t e m = " D a t e " ] } [ D a t a ] , 
 
         A d d e d Y e a r M o n t h N u m b e r   =   T a b l e . A d d C o l u m n ( D i m e n s i o n _ D a t e ,   " Y e a r   M o n t h   N u m b e r " ,   e a c h   [ C a l e n d a r   Y e a r ]   *   1 0 0   +   [ C a l e n d a r   M o n t h   N u m b e r ] ,   I n t 6 4 . T y p e ) 
 
 i n 
 
         A d d e d Y e a r M o n t h N u m b e r 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 2  D a t e   q u e r y   a f t e r   a d d i n g   F i s c a l   Y e a r   M o n t h   N u m b e r 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 l e t 
 
         S o u r c e   =   S q l . D a t a b a s e s ( " l o c a l h o s t " ) , 
 
         W i d e W o r l d I m p o r t e r s D W   =   S o u r c e { [ N a m e = " W i d e W o r l d I m p o r t e r s D W " ] } [ D a t a ] , 
 
         D i m e n s i o n _ D a t e   =   W i d e W o r l d I m p o r t e r s D W { [ S c h e m a = " D i m e n s i o n " , I t e m = " D a t e " ] } [ D a t a ] , 
 
         A d d e d Y e a r M o n t h N u m b e r   =   T a b l e . A d d C o l u m n ( D i m e n s i o n _ D a t e ,   " Y e a r   M o n t h   N u m b e r " ,   e a c h   [ C a l e n d a r   Y e a r ]   *   1 0 0   +   [ C a l e n d a r   M o n t h   N u m b e r ] ,   I n t 6 4 . T y p e ) , 
 
         A d d e d F i s c a l Y e a r M o n t h N u m b e r   =   T a b l e . A d d C o l u m n ( A d d e d Y e a r M o n t h N u m b e r ,   " F i s c a l   Y e a r   M o n t h   N u m b e r " ,   e a c h   [ F i s c a l   Y e a r ]   *   1 0 0   +   [ F i s c a l   M o n t h   N u m b e r ] ,   I n t 6 4 . T y p e ) 
 
 i n 
 
         A d d e d F i s c a l Y e a r M o n t h N u m b e r 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 3  E n t e r e d   d a t a   M   c o d e 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 l e t 
 
         S o u r c e   =   T a b l e . F r o m R o w s ( 
 
                 J s o n . D o c u m e n t ( B i n a r y . D e c o m p r e s s ( 
 
                         B i n a r y . F r o m T e x t ( " i 4 5 W M l S K 1 Q G S B g Y G c A a Y H Q s A   " ,   B i n a r y E n c o d i n g . B a s e 6 4 ) , 
 
                         C o m p r e s s i o n . D e f l a t e ) 
 
                 ) , 
 
                 l e t   _ t   =   ( ( t y p e   t e x t )   m e t a   [ S e r i a l i z e d . T e x t   =   t r u e ] )   i n   t y p e   t a b l e   [ S c a l e   =   _ t ] 
 
         ) , 
 
         # " C h a n g e d   T y p e "   =   T a b l e . T r a n s f o r m C o l u m n T y p e s ( S o u r c e , { { " S c a l e " ,   I n t 6 4 . T y p e } } ) 
 
 i n 
 
         # " C h a n g e d   T y p e " 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 4  S c a l e   t a b l e   f r o m   l i s t 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 l e t 
 
         S o u r c e   =   {   1 ,   1 0 0 0 ,   1 0 0 0 0 0 0   } , 
 
         # " C o n v e r t e d   t o   T a b l e "   =   T a b l e . F r o m L i s t ( S o u r c e ,   S p l i t t e r . S p l i t B y N o t h i n g ( ) ,   n u l l ,   n u l l ,   E x t r a V a l u e s . E r r o r ) , 
 
         # " R e n a m e d   C o l u m n s "   =   T a b l e . R e n a m e C o l u m n s ( # " C o n v e r t e d   t o   T a b l e " , { { " C o l u m n 1 " ,   " S c a l e " } } ) , 
 
         # " C h a n g e d   T y p e "   =   T a b l e . T r a n s f o r m C o l u m n T y p e s ( # " R e n a m e d   C o l u m n s " , { { " S c a l e " ,   I n t 6 4 . T y p e } } ) 
 
 i n 
 
         # " C h a n g e d   T y p e " 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 5  S c a l e   t a b l e   f r o m   r e c o r d s 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 T a b l e . F r o m R e c o r d s   ( 
 
         { 
 
                 [ S c a l e   =   1 ] , 
 
                 [ S c a l e   =   1 0 0 0 ] , 
 
                 [ S c a l e   =   1 0 0 0 0 0 0 ] 
 
         } , 
 
         t y p e   t a b l e   [ S c a l e   =   I n t 6 4 . T y p e ] 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 6  T a b l e   c o n s t r u c t s   i n   M 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 / /   U n t y p e d   c o l u m n s 
 
 # t a b l e   ( 
 
         { " Q u a n t i t y " ,   " U n i t   P r i c e " } , 
 
         { 
 
                 {   2 ,   3   } , 
 
                 {   5 ,   7   } 
 
         } 
 
 ) 
 
 
 
 / /   C o l u m n s   i n   d a t a   t y p e s   d e f i n e d 
 
 # t a b l e   ( 
 
         t y p e   t a b l e   [ Q u a n t i t y   =   I n t 6 4 . T y p e ,   U n i t   P r i c e   =   C u r r e n c y . T y p e ] , 
 
         { 
 
                 {   2 ,   3   } , 
 
                 {   5 ,   7   } 
 
         } 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 7  S c a l e   t a b l e   u s i n g   t h e   t a b l e   c o n s t r u c t   i n   M 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 # t a b l e   ( 
 
         t y p e   t a b l e   [ S c a l e   =   I n t 6 4 . T y p e ] , 
 
         { 
 
                 {   1   } , 
 
                 {   1 0 0 0   } , 
 
                 {   1 0 0 0 0 0 0   } 
 
         } 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 8  C a l c u l a t e d   c o l u m n s 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 T a x P c t   =   S a l e [ T a x   R a t e ]   /   1 0 0 
 
 P r i c e I n c l T a x   =   S a l e [ U n i t   P r i c e ]   *   (   1   +   S a l e [ T a x P c t ]   ) 
 
 D i s c o u n t e d P r i c e I n c l T a x   =   S a l e [ P r i c e I n c l T a x ]   *   0 . 8 
 
 N e w   P r i c e   =   
 
 I F   ( 
 
         S a l e [ D i s c o u n t e d P r i c e I n c l T a x ]   <   2 0 , 
 
         S a l e [ P r i c e I n c l T a x ] , 
 
         S a l e [ D i s c o u n t e d P r i c e I n c l T a x ] 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 9  E x p e n s i v e   S t o c k   I t e m   c a l c u l a t e d   t a b l e   w i t h   F I L T E R 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 E x p e n s i v e   S t o c k   I t e m s   = 
 
 F I L T E R   ( 
 
         ' S t o c k   I t e m ' , 
 
         ' S t o c k   I t e m ' [ U n i t   P r i c e ]   >   3 0 0 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1 0  E x p e n s i v e   o r   G r a y   S t o c k   I t e m   c a l c u l a t e d   t a b l e 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 E x p e n s i v e   o r   G r a y   S t o c k   I t e m s   = 
 
 F I L T E R   ( 
 
         ' S t o c k   I t e m ' , 
 
         O R   ( 
 
                 ' S t o c k   I t e m ' [ U n i t   P r i c e ]   >   3 0 0 , 
 
                 ' S t o c k   I t e m ' [ C o l o r ]   =   " G r a y " 
 
         ) 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1 1  D a y s   i n   M o n t h   c a l c u l a t e d   c o l u m n   w i t h   E A R L I E R 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 D a y s   i n   M o n t h   E A R L I E R   = 
 
 C O U N T R O W S   ( 
 
         F I L T E R   ( 
 
                 ' D a t e ' , 
 
                 ' D a t e ' [ C a l e n d a r   M o n t h   L a b e l ] 
 
                         =   E A R L I E R   (   ' D a t e ' [ C a l e n d a r   M o n t h   L a b e l ]   ) 
 
         ) 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1 2  D a y s   i n   M o n t h   c a l c u l a t e d   c o l u m n   w i t h   V A R 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 D a y s   i n   M o n t h   V A R   = 
 
 V A R   C u r r e n t M o n t h   =   ' D a t e ' [ C a l e n d a r   M o n t h   L a b e l ] 
 
 R E T U R N 
 
         C O U N T R O W S   ( 
 
                 F I L T E R   ( 
 
                         ' D a t e ' , 
 
                         ' D a t e ' [ C a l e n d a r   M o n t h   L a b e l ]   =   C u r r e n t M o n t h 
 
                 ) 
 
         ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1 3  S u m m a r i z i n g   t h e   S a l e   t a b l e 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 M o n t h   S a l e   =   
 
 S U M M A R I Z E   ( 
 
         S a l e , 
 
         ' D a t e ' [ M o n t h ] , 
 
         ' D a t e ' [ C a l e n d a r   M o n t h   N u m b e r ] , 
 
         " S a l e   R o w s " ,   C O U N T R O W S   (   S a l e   ) 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1 4  B u y i n g   G r o u p s 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 B u y i n g   G r o u p s   =   V A L U E S   (   C u s t o m e r [ B u y i n g   G r o u p ]   ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1 5  B u y i n g   G r o u p   f i l t e r e d   t o   o n e   v a l u e 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 W i n g t i p   T o y s   = 
 
 C A L C U L A T E T A B L E   ( 
 
         V A L U E S   (   C u s t o m e r [ B u y i n g   G r o u p ]   ) , 
 
         C u s t o m e r [ B u y i n g   G r o u p ]   =   " W i n g t i p   T o y s " 
 
 ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1 6  R   s c r i p t 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 C o l o r s   < -   d a t a s e t $ C o l o r 
 
 A m o u n t s   < -   d a t a s e t $ ' T o t a l   A c t u a l   A m o u n t '   /   1 0 0 0 0 0 0 
 
 p a r   (   m a r   =   c   (   2 ,   6 ,   2 ,   2   )   +   0 . 1   ) 
 
 b a r p l o t   (   A m o u n t s ,   h o r i z   =   T R U E ,   n a m e s . a r g   =   C o l o r s ,   l a s   =   1   ) 
 
 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 L I S T I N G   2 - 1 7  R e p o r t   t h e m e   J S O N 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 { 
 
         " n a m e " :   " E R 7 7 8 " , 
 
         " d a t a C o l o r s " :   [ " # 7 1 7 1 7 1 " ,   " # F 1 5 9 5 E " ,   " # 7 9 C 3 6 9 " ,   " # 5 8 9 A D 3 " ,   " # F 9 A 6 5 9 " ,   " # D 7 7 F B 2 " ,   " # C E 7 0 5 8 " ,   " # 9 E 6 7 A B " ] , 
 
         " v i s u a l S t y l e s " :   { 
 
                 " * " :   { 
 
                         " * " :   { 
 
                                 " * " :   [ { 
 
                                         " f o n t S i z e " :   1 0 , 
 
                                         " c o l o r " :   { 
 
                                                 " s o l i d " :   { 
 
                                                         " c o l o r " :   " # 0 0 0 0 0 0 " 
 
                                                 } 
 
                                         } 
 
                                 } ] 
 
                         } 
 
                 } 
 
         } 
 
 } 